

! Huistaak 1: Technisch-Wetenschappelijke Software
!
! Tuur Stuyck
! s0200995
! 1e Master Wiskundige Ingenieurstechnieken
!
! matrix_stats
! gespendeerde tijd: 1.5u
! 
! getest met gfortran version 4.7.0, G95 version 0.92, 
! gfortran -o matrix_stats matrix_stats.f95
! g95 -o matrix_stats matrix_stats.f95

! Program Output gfortran:
! ---------------
! Aantal rijen:            4
! Aantal kolommen:            4
! Aantal elementen:           16
! Grootste waarde in matrix:    1.0000000    
! Kleinste waarde in matrix:   6.25000000E-02
! Ondergrens indices rijen en kolommen:            1           1
! Bovengrens indices rijen en kolommen:            4           4
! Som rij            1 :    2.1250000    
! Som rij            2 :    2.1250000    
! Som rij            3 :    2.1250000    
! Som rij            4 :    2.1250000    
! Som kolom            1 :    2.1250000    
! Som kolom            2 :    2.1250000    
! Som kolom            3 :    2.1250000    
! Som kolom            4 :    2.1250000    
! Aantal rijen:            7
! Aantal kolommen:            3
! Aantal elementen:           21
! Grootste waarde in matrix:    1.9091001    
! Kleinste waarde in matrix:   9.09089968E-02
! Ondergrens indices rijen en kolommen:           -3           0
! Bovengrens indices rijen en kolommen:            3           2
! Som rij           -3 :    3.0000200    
! Som rij           -2 :    3.0000100    
! Som rij           -1 :    3.0000401    
! Som rij            0 :    2.9999499    
! Som rij            1 :    2.9999499    
! Som rij            2 :    3.0000088    
! Som rij            3 :    3.0000200    
! Som kolom            0 :    6.9999399    
! Som kolom            1 :    7.0000300    
! Som kolom            2 :    7.0000291    

! start programma
program matrix_stats

! initialisatie parameters
implicit none
integer :: i
real, dimension(4,4), target :: something_special = reshape( (/ &
1.0000e+00, 1.2500e-01, 1.8750e-01, 8.1250e-01, &
3.1250e-01, 6.8750e-01, 6.2500e-01, 5.0000e-01, &
5.6250e-01, 4.3750e-01, 3.7500e-01, 7.5000e-01, &
2.5000e-01, 8.7500e-01, 9.3750e-01, 6.2500e-02 &
/), (/ 4,4 /), order=(/2,1/) )

real, dimension(-3:3,0:2), target :: different_special = reshape( (/ & 
9.0909e-01,1.9091e+00,8.1818e-01,1.4545e+00,4.5455e-01, &
1.2727e+00,1.8182e-01,2.7273e-01,3.6364e-01,6.3636e-01, &
1.0000e+00,1.3636e+00,1.6364e+00,1.7273e+00,1.8182e+00, &
7.2727e-01,1.5455e+00,5.4545e-01,1.1818e+00,9.0909e-02, &
1.0909e+00 /), (/7,3/), order=(/1,2/) )

! Gebruik pointers om indices in matrix te behouden
real, dimension(:,:), pointer :: pointer_something_special(:,:), pointer_different_special(:,:)
pointer_something_special => something_special
pointer_different_special => different_special
call show_properties(pointer_something_special)
call show_properties(pointer_different_special)

contains

subroutine show_properties(matrix)

real, dimension(:,:), pointer :: matrix
integer, dimension(2) :: sizeMatrix
! bereken en print eigenschappen matrix
sizeMatrix = ubound(matrix) - (lbound(matrix)-1)    
print *, 'Aantal rijen: ', sizeMatrix(1)
print *, 'Aantal kolommen: ', sizeMatrix(2)
print *, 'Aantal elementen: ', sizeMatrix(1)*sizeMatrix(2)
print *, 'Grootste waarde in matrix: ', maxval(matrix)
print *, 'Kleinste waarde in matrix: ', minval(matrix)
print *, 'Ondergrens indices rijen en kolommen: ', lbound(matrix) 
print *, 'Bovengrens indices rijen en kolommen: ', ubound(matrix) 
! som rijen
do i = lbound(matrix,1) , ubound(matrix,1)
print *, "Som rij ", i, ": ", sum(matrix(i,:)) 
end do
! som kolommen
do i = lbound(matrix,2) , ubound(matrix,2)
print *, "Som kolom ", i, ": ", sum(matrix(:,i))
end do

end subroutine

end program


